package com.sambo.inspection.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sambo.inspection.R;
import com.sambo.inspection.activity.InformationQueryActivity;
import com.sambo.inspection.activity.MainActivity;
import com.sambo.inspection.activity.MessageActivity;
import com.sambo.inspection.activity.OptionActivity;
import com.sambo.inspection.common.image.GlideImageLoader;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;

import java.util.ArrayList;
import java.util.List;

public class SummaryFragment extends Fragment implements View.OnClickListener {

    LinearLayout llLastMessage;

    TextView tvLastMessage;

    Banner banner;

    LinearLayout llRoutingInspectionTask;
    LinearLayout llRoutingInspectionRecord;
    LinearLayout llEventReport;
    LinearLayout llWorkOrder;
    LinearLayout llSelectInfo;
    LinearLayout llOption;

    private List<String> mImageUrlList;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View contentView = inflater.inflate(R.layout.fragment_summary, null);
        llLastMessage = contentView.findViewById(R.id.ll_last_message);
        tvLastMessage = contentView.findViewById(R.id.tv_last_message);
        banner = contentView.findViewById(R.id.banner);
        llRoutingInspectionTask = contentView.findViewById(R.id.ll_routing_inspection_task);
        llRoutingInspectionRecord = contentView.findViewById(R.id.ll_routing_inspection_record);
        llEventReport = contentView.findViewById(R.id.ll_event_report);
        llWorkOrder = contentView.findViewById(R.id.ll_work_order);
        llSelectInfo = contentView.findViewById(R.id.ll_select_info);
        llOption = contentView.findViewById(R.id.ll_option);

        mImageUrlList = new ArrayList<>();
        mImageUrlList.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1550724943361&di=6f89d5f6dc0c95d8dbc362b0c59e274a&imgtype=0&src=http%3A%2F%2Fimg67.hbzhan.com%2F9%2F20151019%2F635808657133009174192.jpg");
        mImageUrlList.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1550724987616&di=6afd245beecfb8a743294cc04f3b81f1&imgtype=0&src=http%3A%2F%2Fwww.cscyw.com%2Fuploads%2Fimages%2Fimage%2F20160115_195315_4504.jpg");
        mImageUrlList.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1551319885&di=eee6d9506809573f037b9b44f73d2aaa&imgtype=jpg&er=1&src=http%3A%2F%2Fnews.sipac.gov.cn%2Fspecial%2F201212zxgy%2Fcxgl%2F201212%2FW020121227635055115942.jpg");
        mImageUrlList.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1550725204482&di=2487027f084aead3df6dfd6cb6f3edd6&imgtype=0&src=http%3A%2F%2Fwww.cecep.cn%2FPortals%2F0%2Fdownload%2Fc7c951ef06fc47bba9eb02230d557913.jpg");

        //设置banner样式
//        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE);
        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        //设置图片加载器
        banner.setImageLoader(new GlideImageLoader());
        //设置图片集合
        banner.setImages(mImageUrlList);
        //设置banner动画效果
        banner.setBannerAnimation(Transformer.DepthPage);
//        //设置标题集合（当banner样式有显示title时）
//        banner.setBannerTitles(titles);
        //设置自动轮播，默认为true
        banner.isAutoPlay(true);
        //设置轮播时间
        banner.setDelayTime(2000);
        //设置指示器位置（当banner模式中有指示器时）
        banner.setIndicatorGravity(BannerConfig.RIGHT);
        //banner设置方法全部调用完毕时最后调用
        banner.start();

        llLastMessage.setOnClickListener(this);
        llRoutingInspectionTask.setOnClickListener(this);
        llRoutingInspectionRecord.setOnClickListener(this);
        llEventReport.setOnClickListener(this);
        llWorkOrder.setOnClickListener(this);
        llSelectInfo.setOnClickListener(this);
        llOption.setOnClickListener(this);

        return contentView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onResume() {
        super.onResume();
        //开始轮播
        banner.startAutoPlay();
    }

    @Override
    public void onPause() {
        super.onPause();
        //结束轮播
        banner.stopAutoPlay();
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_last_message:
                Intent msgIntent = new Intent(getContext(), MessageActivity.class);
                startActivity(msgIntent);
                break;
            case R.id.ll_routing_inspection_task:
                ((MainActivity) getActivity()).showRoutingInspectionTask();
                break;
            case R.id.ll_routing_inspection_record:
                ((MainActivity) getActivity()).showRoutingInspectionRecord();
                break;
            case R.id.ll_event_report:
                ((MainActivity) getActivity()).showEventReport();
                break;
            case R.id.ll_work_order:
                ((MainActivity) getActivity()).showWorkOrder();
                break;
            case R.id.ll_select_info:
                Intent infoIntent = new Intent(getContext(), InformationQueryActivity.class);
                startActivity(infoIntent);
                break;
            case R.id.ll_option:
                Intent opIntent = new Intent(getContext(), OptionActivity.class);
                startActivity(opIntent);
                break;
        }
    }

    public void setLastMessage(String title) {
        if (tvLastMessage != null) {
            tvLastMessage.setText(title);
        }
    }
}
